/// 
/// Author: Jeff Liu
/// Date: 2023-04-14 11:53:51
/// LastEditTime: 2023-05-05 09:25:54
/// LastEditors: Jeff Liu
/// Description: 
/// FilePath: /HCC3T/src/HCC/SVR/PubSub/Subscriber.cls
/// Jeff.liu@intersytems.com
/// 
Class HCC.SVR.PubSub.Subscriber Extends (%Persistent, %XML.Adaptor, %JSON.Adaptor) [ DdlAllowed ]
{

/// 订阅者名称
Property SubscriberName As %String [ Required ];

/// 系统或个人
Property Role As %String(VALUELIST = ",System,Person") [ InitialExpression = "System", Required ];

/// 发布时的优先级
Property Priority As %String(VALUELIST = ",Low,Normal,High") [ InitialExpression = "Normal", Required ];

/// 是否活动
Property IsActive As %Boolean [ InitialExpression = 1, Required ];

/// 停用原因
Property InActiveReason As %String(DISPLAYLIST = ",用户停用,订阅时间到期", VALUELIST = ",U,T");

// 数据转换名

// Property Transform As %String;

/// 目标业务操作
Property Target As %String;

/// 个人联系方式，电子邮件、微信、钉钉...
Property PersonalContactName As %String;

/// 个人联系方式类型，电子邮件、微信、钉钉...
Property PersonalContact As %String;

Property CreatedAt As %TimeStamp [ InitialExpression = {$ZDATETIME($ZDATETIMEH($ZTIMESTAMP,-3),3,1,4)} ];

/// 创建时间
/// 订户名字不可以重复
Index IdxSubscriberName On SubscriberName [ Unique ];

// Index IdxTarget On Target [ Unique ];

/// 删除订阅者时，删除订阅关系
Trigger CleanSubscription [ Event = DELETE, Foreach = row/object, Time = AFTER ]
{
   
    New id,SQLCODE
    Set id = {ID}
    &SQL(DELETE FROM HCC_SVR_PubSub.Subscription WHERE Subscriber = :id)
    If SQLCODE<0 
    {
        Set baderr="SQLCODE ERROR:"_SQLCODE_" "_%msg
    Set %ok=0         
    Return baderr 
    }
}


}
